package com.cellulam.framework.datasource.service;

import com.cellulam.framework.core.enums.AppStatus;
import com.cellulam.framework.core.exceptions.SysException;
import com.cellulam.framework.core.model.Id;
import com.cellulam.framework.core.model.Status;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

@Slf4j
public abstract class BaseAppStatusDtoService<PK, BEAN extends Serializable & Id<PK>, REQ extends Status<PK>, RESP extends Serializable>
        extends BaseUpdateUserDtoService<PK, BEAN, REQ, RESP> {

    public void enable(PK id) {
        this.updateStatus(id, AppStatus.ENABLE);
    }

    public void disable(PK id) {
        this.updateStatus(id, AppStatus.DISABLE);
    }

    public void updateStatus(PK id, AppStatus status) {
        REQ request = null;
        try {
            request = reqClass.getConstructor().newInstance();
        } catch (Exception e) {
            log.error("", e);
            throw new SysException(e);
        }
        request.setId(id);
        request.setStatus(status.getCode());
        this.update(request);
    }
}

